﻿//Manimaran

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualBasic.FileIO;

namespace Tzync
{
    public class FileOperations
    {
        private String storeFilesDir;
        private SafeSync safeSync;
        private Queue<String> fileQueue; // a queue to delete files in Hard Disk. For safe sync.

        public FileOperations(String storeFilesDir, SafeSync safeSync)
        {
            this.storeFilesDir = storeFilesDir;
            this.safeSync = safeSync;
            fileQueue = new Queue<String>();
        }

        public TreeNode Creation(TreeNode tNode, Difference diff, SystemType systemName)
        {
            String parsedDateTime;
            String customFilePath = "";
            FileInfo fileInfo;

            parsedDateTime = Utility.ParseDateTime(diff.GetSysFile().LastWriteTime);

            if (diff.GetPairType().First == DirectionType.SystemToHD)
            {
                if (systemName == SystemType.Host)
                {
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if got then juz delete it
                    File.Copy(tNode.GetFullPathHost(), customFilePath);

                }
                else
                {
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                    if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                    File.Copy(tNode.GetFullPathGuest(), customFilePath);
                }
            }
            else if (diff.GetPairType().First == DirectionType.HDToSystem)
            {
                if (systemName == SystemType.Host)
                {
                    // Copy file to system
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathHost());

                    // Perform safe sync
                    safeSync.Append(SafeSyncType.Create, tNode.GetFullPathHost());

                    // Update treeNode members
                    tNode.GetVersionHost().First = tNode.GetVersionGuest().First;
                    tNode.GetVersionHost().Second = tNode.GetVersionGuest().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathHost());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncHost(parsedDateTime);
                }
                else
                {
                    //copyFromHDToSystem(storeFilesDir, tNode, type);
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathGuest());

                    // Perform safe sync
                    safeSync.Append(SafeSyncType.Create, tNode.GetFullPathGuest());

                    // Update treeNode members
                    tNode.GetVersionGuest().First = tNode.GetVersionHost().First;
                    tNode.GetVersionGuest().Second = tNode.GetVersionHost().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathGuest());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncGuest(parsedDateTime);
                }
                fileQueue.Enqueue(customFilePath);
            }
            return tNode;
        }

        public TreeNode Deletion(TreeNode tNode, Difference diff, SystemType systemName)
        {
            String parsedDateTime;

            parsedDateTime = Utility.ParseDateTime(diff.GetSysFile().LastWriteTime);

            if (diff.GetPairType().First == DirectionType.SystemToHD)
            {
                if (systemName == SystemType.Host)
                {
                    // Update treeNode members
                    tNode.GetVersionHost().First = -1;
                    tNode.GetVersionHost().Second = 0;
                    parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                    tNode.SetSyncHost(parsedDateTime);

                    if (tNode.GetVersionGuest().First == 0 && tNode.GetVersionGuest().Second == 0)
                    {
                        tNode.Isdeleted = true;
                    }

                }
                else
                {
                    // Update treeNode members
                    tNode.GetVersionGuest().First = 0;
                    tNode.GetVersionGuest().Second = -1;
                    parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                    tNode.SetSyncGuest(parsedDateTime);

                    if (tNode.GetVersionHost().First == 0 && tNode.GetVersionHost().Second == 0)
                    {
                        tNode.Isdeleted = true;
                    }
                }
            }
            else if (diff.GetPairType().First == DirectionType.HDToSystem)
            {
                if (systemName == SystemType.Host)
                {
                    if (File.Exists(tNode.GetFullPathHost()))
                    {
                        //File.Delete(tNode.GetFullPathHost());
                        FileSystem.DeleteFile(tNode.GetFullPathHost(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                        // Perform safe sync
                        safeSync.Append(SafeSyncType.Delete, tNode.GetFullPathHost());
                    }

                    // Update treeNode members
                    tNode.GetVersionHost().First = tNode.GetVersionGuest().First;
                    tNode.GetVersionHost().Second = tNode.GetVersionGuest().Second;
                    parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                    tNode.SetSyncHost(parsedDateTime);

                    // Mark file to be removed from metadata
                    tNode.Isdeleted = true;
                }
                else
                {
                    if (File.Exists(tNode.GetFullPathGuest()))
                    {
                        //File.Delete(tNode.GetFullPathGuest());
                        FileSystem.DeleteFile(tNode.GetFullPathGuest(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                        // Perform safe sync
                        safeSync.Append(SafeSyncType.Delete, tNode.GetFullPathHost());
                    }

                    // Update treeNode members
                    tNode.GetVersionGuest().First = tNode.GetVersionHost().First;
                    tNode.GetVersionGuest().Second = tNode.GetVersionHost().Second;
                    parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                    tNode.SetSyncGuest(parsedDateTime);

                    // Mark file to be removed from metadata
                    tNode.Isdeleted = true;
                }
            }
            return tNode;
        }

        public TreeNode Modification(TreeNode tNode, Difference diff, SystemType systemName)
        {
            String parsedDateTime;
            String customFilePath = "";
            FileInfo fileInfo;

            parsedDateTime = Utility.ParseDateTime(diff.GetSysFile().LastWriteTime);

            if (diff.GetPairType().First == DirectionType.SystemToHD)
            {
                if (systemName == SystemType.Host)
                {
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                    File.Copy(tNode.GetFullPathHost(), customFilePath);

                    // Update treeNode members
                    tNode.GetVersionHost().First++;
                    fileInfo = new FileInfo(tNode.GetFullPathHost());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncHost(parsedDateTime);
                }
                else
                {
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                    if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                    File.Copy(tNode.GetFullPathGuest(), customFilePath);

                    // Update treeNode members
                    tNode.GetVersionGuest().Second++;
                    fileInfo = new FileInfo(tNode.GetFullPathGuest());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncGuest(parsedDateTime);
                }
            }
            else if (diff.GetPairType().First == DirectionType.HDToSystem)
            {                
                if (systemName == SystemType.Host)
                {                    
                    if (File.Exists(tNode.GetFullPathHost()))
                    {
                        //File.Delete(tNode.GetFullPathHost());
                        FileSystem.DeleteFile(tNode.GetFullPathHost(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                        // Perform safe sync
                        safeSync.Append(SafeSyncType.Modify, tNode.GetFullPathHost());
                    }                    
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));                    
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathHost());                    

                    // Update treeNode members
                    tNode.GetVersionHost().First = tNode.GetVersionGuest().First;
                    tNode.GetVersionHost().Second = tNode.GetVersionGuest().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathHost());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncHost(parsedDateTime);
                }
                else
                {
                    if (File.Exists(tNode.GetFullPathGuest()))
                    {
                        //File.Delete(tNode.GetFullPathGuest());
                        FileSystem.DeleteFile(tNode.GetFullPathGuest(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                        // Perform safe sync
                        safeSync.Append(SafeSyncType.Modify, tNode.GetFullPathGuest());
                    }
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathGuest());

                    // Update treeNode members
                    tNode.GetVersionGuest().First = tNode.GetVersionHost().First;
                    tNode.GetVersionGuest().Second = tNode.GetVersionHost().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathGuest());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncGuest(parsedDateTime);
                }
                fileQueue.Enqueue(customFilePath);
            }
            return tNode;
        }

        public TreeNode ModMod(TreeNode tNode, Difference diff, SystemType systemName)
        {
            String parsedDateTime;
            String customFilePath = "";
            FileInfo fileInfo;

            parsedDateTime = Utility.ParseDateTime(diff.GetSysFile().LastWriteTime);

            if (diff.GetPairType().First == DirectionType.SystemToHD)
            {
                if (systemName == SystemType.Host)
                {
                    // delete B's file in HD since user want to propagate system file to HD
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                    File.Delete(customFilePath);

                    // copy system file to HD now
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    if (File.Exists(customFilePath)) File.Delete(customFilePath); 
                    File.Copy(tNode.GetFullPathHost(), customFilePath);

                    // Update treeNode members
                    tNode.GetVersionHost().First++;
                    fileInfo = new FileInfo(tNode.GetFullPathHost());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncHost(parsedDateTime);
                }
                else
                {
                    // delete A's file in HD since user want to propagate system file to HD
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    File.Delete(customFilePath);

                    // copy system file to HD now
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                    if (File.Exists(customFilePath)) File.Delete(customFilePath); 
                    File.Copy(tNode.GetFullPathGuest(), customFilePath);

                    // Update treeNode members
                    tNode.GetVersionGuest().Second++;
                    fileInfo = new FileInfo(tNode.GetFullPathGuest());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncGuest(parsedDateTime);
                }
            }
            else if (diff.GetPairType().First == DirectionType.HDToSystem)
            {
                if (systemName == SystemType.Host)
                {
                    //File.Delete(tNode.GetFullPathHost());
                    FileSystem.DeleteFile(tNode.GetFullPathHost(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathHost());

                    // Perform safe sync
                    safeSync.Append(SafeSyncType.Modify, tNode.GetFullPathHost());

                    // Update treeNode members
                    tNode.GetVersionHost().First = tNode.GetVersionGuest().First;
                    tNode.GetVersionHost().Second = tNode.GetVersionGuest().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathHost());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncHost(parsedDateTime);
                }
                else
                {
                    //File.Delete(tNode.GetFullPathGuest());
                    FileSystem.DeleteFile(tNode.GetFullPathGuest(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathGuest());

                    // Perform safe sync
                    safeSync.Append(SafeSyncType.Modify, tNode.GetFullPathGuest());

                    // Update treeNode members
                    tNode.GetVersionGuest().First = tNode.GetVersionHost().First;
                    tNode.GetVersionGuest().Second = tNode.GetVersionHost().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathGuest());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncGuest(parsedDateTime);
                }
                fileQueue.Enqueue(customFilePath);
            }
            return tNode;
        }

        public TreeNode ModDelete(TreeNode tNode, Difference diff, SystemType systemName)
        {
            String parsedDateTime;
            String customFilePath = "";
            FileInfo fileInfo;

            parsedDateTime = Utility.ParseDateTime(diff.GetSysFile().LastWriteTime);

            if (diff.GetPairType().First == DirectionType.SystemToHD)
            {
                if (systemName == SystemType.Host)
                {
                    if (tNode.GetVersionGuest().First == 0 && tNode.GetVersionGuest().Second == -1)
                    {
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                        File.Copy(tNode.GetFullPathHost(), customFilePath);

                        // Update treeNode members
                        tNode.GetVersionHost().First++;
                        fileInfo = new FileInfo(tNode.GetFullPathHost());
                        parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                        tNode.SetSyncHost(parsedDateTime);
                    }
                    else
                    {
                        // Update treeNode members
                        tNode.GetVersionHost().First = -1;
                        tNode.GetVersionHost().Second = 0;
                        parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                        tNode.SetSyncHost(parsedDateTime);

                        // Delete file in HD after conflict resolution chose to ignore this file
                        // Analyze uses this to check if conflict was resolved in a previous sync in this pc
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath);
                    }

                }
                else
                {
                    if (tNode.GetVersionHost().First == -1 && tNode.GetVersionHost().Second == 0)
                    {
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                        File.Copy(tNode.GetFullPathGuest(), customFilePath);

                        // Update treeNode members
                        tNode.GetVersionGuest().Second++;
                        fileInfo = new FileInfo(tNode.GetFullPathGuest());
                        parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                        tNode.SetSyncGuest(parsedDateTime);
                    }
                    else
                    {
                        // Update treeNode members
                        tNode.GetVersionGuest().First = 0;
                        tNode.GetVersionGuest().Second = -1;
                        parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                        tNode.SetSyncGuest(parsedDateTime);

                        // Delete file in HD after conflict resolution chose to ignore this file
                        // Analyze uses this to check if conflict was resolved in a previous sync in this pc
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath);
                    }
                }
            }
            else if (diff.GetPairType().First == DirectionType.HDToSystem)
            {
                if (systemName == SystemType.Host)
                {
                    if (tNode.GetVersionGuest().First == 0 && tNode.GetVersionGuest().Second == -1)
                    {
                        if (File.Exists(tNode.GetFullPathHost()))
                        {
                            //File.Delete(tNode.GetFullPathHost());
                            FileSystem.DeleteFile(tNode.GetFullPathHost(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                            // Perform safe sync
                            safeSync.Append(SafeSyncType.Delete, tNode.GetFullPathHost());
                        }

                        // Update treeNode members
                        tNode.GetVersionHost().First = tNode.GetVersionGuest().First;
                        tNode.GetVersionHost().Second = tNode.GetVersionGuest().Second;
                        parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                        tNode.SetSyncHost(parsedDateTime);

                        // Mark file to be removed from metadata
                        tNode.Isdeleted = true;
                    }
                    else
                    {
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                        File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathHost());

                        // Perform safe sync
                        safeSync.Append(SafeSyncType.Modify, tNode.GetFullPathHost());

                        // Update treeNode members
                        tNode.GetVersionHost().First = tNode.GetVersionGuest().First;
                        tNode.GetVersionHost().Second = tNode.GetVersionGuest().Second;
                        fileInfo = new FileInfo(tNode.GetFullPathHost());
                        parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                        tNode.SetSyncHost(parsedDateTime);

                        //Delete file in HD
                        fileQueue.Enqueue(customFilePath);
                    }

                }
                else
                {
                    if (tNode.GetVersionHost().First == -1 && tNode.GetVersionHost().Second == 0)
                    {
                        if (File.Exists(tNode.GetFullPathGuest()))
                        {
                            //File.Delete(tNode.GetFullPathGuest());
                            FileSystem.DeleteFile(tNode.GetFullPathGuest(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);

                            // Perform safe sync
                            safeSync.Append(SafeSyncType.Delete, tNode.GetFullPathGuest());
                        }

                        // Update treeNode members
                        tNode.GetVersionGuest().First = tNode.GetVersionHost().First;
                        tNode.GetVersionGuest().Second = tNode.GetVersionHost().Second;
                        parsedDateTime = Utility.ParseDateTime(DateTime.Now);
                        tNode.SetSyncGuest(parsedDateTime);

                        // Mark file to be removed from metadata
                        tNode.Isdeleted = true;
                    }
                    else
                    {
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                        File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathGuest());

                        // Perform safe sync
                        safeSync.Append(SafeSyncType.Modify, tNode.GetFullPathGuest());

                        // Update treeNode members
                        tNode.GetVersionGuest().First = tNode.GetVersionHost().First;
                        tNode.GetVersionGuest().Second = tNode.GetVersionHost().Second;
                        fileInfo = new FileInfo(tNode.GetFullPathGuest());
                        parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                        tNode.SetSyncGuest(parsedDateTime);

                        //Delete file in HD
                        fileQueue.Enqueue(customFilePath);
                    }
                }
            }
            return tNode;

        }

        public TreeNode CreationCreation(TreeNode tNode, Difference diff, SystemType systemName)
        {
            String parsedDateTime;
            String customFilePath = "";
            FileInfo fileInfo;

            parsedDateTime = Utility.ParseDateTime(diff.GetSysFile().LastWriteTime);

            if (diff.GetPairType().First == DirectionType.SystemToHD)
            {
                    if (systemName == SystemType.Host)
                    {
                        // User chooses to propagate to other computer. So delete B's file in HD
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it

                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                        File.Copy(tNode.GetFullPathHost(), customFilePath);

                        // Update treeNode members
                        tNode.GetVersionHost().First++;
                        fileInfo = new FileInfo(tNode.GetFullPathHost());
                        parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                        tNode.SetSyncHost(parsedDateTime);
                    }
                    else
                    {
                        // User chooses to propagate to other computer. So delete A's file in HD
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                        
                        customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                        if (File.Exists(customFilePath)) File.Delete(customFilePath); // check if earlier file exits. if then juz delete it
                        File.Copy(tNode.GetFullPathGuest(), customFilePath);

                        // Update treeNode members
                        tNode.GetVersionGuest().Second++;
                        fileInfo = new FileInfo(tNode.GetFullPathGuest());
                        parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                        tNode.SetSyncGuest(parsedDateTime);
                    }
                }
            else if (diff.GetPairType().First == DirectionType.HDToSystem)
            {
                if (systemName == SystemType.Host)
                {
                    if (File.Exists(tNode.GetFullPathHost()))
                    {
                        //File.Delete(tNode.GetFullPathHost());
                        FileSystem.DeleteFile(tNode.GetFullPathHost(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                    }
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathGuest()));
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathHost());

                    // Perform safe sync
                    safeSync.Append(SafeSyncType.Create, tNode.GetFullPathHost());

                    // Update treeNode members
                    tNode.GetVersionHost().First = tNode.GetVersionGuest().First;
                    tNode.GetVersionHost().Second = tNode.GetVersionGuest().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathHost());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncHost(parsedDateTime);
                }
                else
                {
                    if (File.Exists(tNode.GetFullPathGuest()))
                    {
                        //File.Delete(tNode.GetFullPathGuest());
                        FileSystem.DeleteFile(tNode.GetFullPathGuest(), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                    }
                    customFilePath = Path.Combine(storeFilesDir, Utility.StripString(tNode.GetFullPathHost()));
                    File.Copy(Path.Combine(storeFilesDir, customFilePath), tNode.GetFullPathGuest());

                    // Perform safe sync
                    safeSync.Append(SafeSyncType.Create, tNode.GetFullPathGuest());

                    // Update treeNode members
                    tNode.GetVersionGuest().First = tNode.GetVersionHost().First;
                    tNode.GetVersionGuest().Second = tNode.GetVersionHost().Second;
                    fileInfo = new FileInfo(tNode.GetFullPathGuest());
                    parsedDateTime = Utility.ParseDateTime(fileInfo.LastWriteTime);
                    tNode.SetSyncGuest(parsedDateTime);
                }
                //Delete file in HD
                fileQueue.Enqueue(customFilePath);
            }
            return tNode;
        }

        public TreeNode DeletionDeletion(TreeNode tNode, Difference diff, SystemType systemName)
        {
            // Mark file to be removed from metadata
            tNode.Isdeleted = true;
            return tNode;
        }

        public void DeleteFilesinHD()
        {
            try
            {
                foreach (String str in fileQueue)
                {
                    if (File.Exists(str)) File.Delete(str);
                }
            }
            catch (UnauthorizedAccessException)
            {
                throw new UnauthorizedAccessException("File", ActionType.Sync);
            }
            catch (FileNotFoundException)
            {
                throw new UnauthorizedAccessException("File", ActionType.Sync);
            }
            catch (PathTooLongException)
            {
                throw new UnauthorizedAccessException("File", ActionType.Sync);
            }
        }
    }
}
